//
//  BaseTableViewController.swift
//  微博001
//
//  Created by apple on 15/12/12.
//  Copyright © 2015年 apple. All rights reserved.
//

import UIKit
//根据用户时候登陆 去显示访问视图 还是表视图
class BaseTableViewController: UITableViewController,VisitorLoginViewDelegate {
    //设置用户时候登陆标记
    var userLogin = UserAccountMode().userLogin
    
    
    //新建属性访客视图
    var visitorLoginView: VisitorLoginView?
    
    //添加自定义下拉刷新控件
    lazy var refreshView: WBRefreshControl = WBRefreshControl()
    
    //如果检测到view(更试图)为nil 会自动调用loadView
    //苹果专门为手码开发准备的,一旦实现了该方法,  sb/xib自动失效
    
    override func loadView() {
        
        if userLogin {
            //调用父类的loadView() 方法就会自动创建TabView
            super.loadView()
        }else {
            setVisitorLoginView()
        }
        
        
    }
    
    //访问者
    func setVisitorLoginView() {
        
       visitorLoginView = VisitorLoginView()

        visitorLoginView?.visitroViewDelegate = self
        view = visitorLoginView
        
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "userWillLogin")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "userWillRegister")
 
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

  
    }
    
    

    func userWillLogin() {
        let webView = OAuthViewController()
        let nav = UINavigationController(rootViewController: webView)
        presentViewController(nav, animated: true, completion: nil)
    }
    
    func userWillRegister() {
        print(__FUNCTION__)

    }
 

}
